﻿using Engine.Graphics;
using Engine.Graphics.VertexStructures;
using SharpDX;
using System.Collections.Generic;

namespace WorldRacing2.StreetAddin
{
    internal class ForestBorderAddon
    {
        #region Internal Methods

        internal static List<IGameVertex> CreateGameVerticesForForest(Vector3[] middle, float widthPointOne, float widthPointTwo, float textureScale,
           float textureUcoordinatesData, float[] middleLineDistances, float lengthOfStreet, ForestBorderAddinAddon.ForestBorderData data)
        {
            List<IGameVertex> verticesWr2Data;

            float percentofStreet = 0;
            float streetwidth = 0;
            Color4 diffuseColor = data.diffuseColor;
            verticesWr2Data = new List<IGameVertex>();

            verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, 0f,
                textureUcoordinatesData, 0f,
                data.vertexColor, diffuseColor));

            verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, -1f,
                textureUcoordinatesData, -1f,
               data.vertexColor, diffuseColor));

            textureUcoordinatesData -= (middleLineDistances[0] / widthPointOne) * textureScale;

            for (int i = 1; i < (middle.Length - 1); i++)
            {
                percentofStreet += middleLineDistances[i - 1];
                streetwidth = widthPointOne - ((widthPointOne - widthPointTwo) * (percentofStreet / lengthOfStreet));

                verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, 0f,
                    textureUcoordinatesData, 0f,
                   data.vertexColor, diffuseColor));

                verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, -1f,
                    textureUcoordinatesData, -1f,
                   data.vertexColor, diffuseColor));

                textureUcoordinatesData -= (middleLineDistances[i] / streetwidth) * textureScale;
            }

            verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, 0f,
                textureUcoordinatesData, 0f,
                data.vertexColor, diffuseColor));

            verticesWr2Data.Add(new MyOwnVertex.Wr2Data(textureUcoordinatesData, -1f,
                textureUcoordinatesData, -1f,
                data.vertexColor, diffuseColor));

            return verticesWr2Data;
        }

        #endregion Internal Methods
    }
}